//
//  KnowledgeTableViewCell.m
//  Menu
//
//  Created by YouLu on 15/7/4.
//  Copyright (c) 2015年 lijiangang. All rights reserved.
//

#import "KnowledgeTableViewCell.h"

@implementation KnowledgeTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews
{
    self.knowledgeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(40*WIDTH, 10*HEIGHT, 295*WIDTH, 190*HEIGHT)];
    [self.contentView addSubview:self.knowledgeImageView];
    [_knowledgeImageView release];
    
    self.knowledgeLabel = [[UILabel alloc] initWithFrame:CGRectMake(40*WIDTH, 210*HEIGHT, 295*WIDTH, 100*HEIGHT)];
    self.knowledgeLabel.numberOfLines = 0;
    [self.contentView addSubview:self.knowledgeLabel];
    [_knowledgeLabel release];
    
    self.makeLabel = [[UILabel alloc] initWithFrame:CGRectMake(40*WIDTH, 350*HEIGHT, 80*WIDTH, 30*HEIGHT)];
    self.makeLabel.text = @"制作指导";
    self.makeLabel.font = [UIFont systemFontOfSize:20];
    [self.contentView addSubview:self.makeLabel];
    [_makeLabel release];
    
    self.makeContentLabel = [[UILabel alloc] initWithFrame:CGRectMake(40*WIDTH, 390*HEIGHT, 295*WIDTH, 100*HEIGHT)];
    self.makeContentLabel.numberOfLines = 0;
    [self.contentView addSubview:self.makeContentLabel];
    [_makeContentLabel release];
    
}
-(void)setKnowModel:(KnowModel *)knowModel
{
    if (_knowModel != knowModel) {
        [_knowModel release];
        _knowModel = [knowModel retain];
        
    }
    [self.knowledgeImageView sd_setImageWithURL:[NSURL URLWithString:self.knowModel.imagePath]];
    
    CGFloat height = [[self class] heightForcell:self.knowModel.nutritionAnalysis];
    self.knowledgeLabel.frame = CGRectMake(40*WIDTH, 210*HEIGHT, 295*WIDTH, height);
    self.makeLabel.frame = CGRectMake(40*WIDTH, (210+10)*HEIGHT+height, 200*WIDTH, 40*HEIGHT);
    self.knowledgeLabel.text = self.knowModel.nutritionAnalysis;
    CGFloat makeContentHeight = [[self class] heightForcell:self.knowModel.productionDirection];
    self.makeContentLabel.frame = CGRectMake(40*WIDTH, height+(210+10+40)*HEIGHT, 295*WIDTH, makeContentHeight);
    self.makeContentLabel.text = self.knowModel.productionDirection;
    
}
//-------------------字体高度----------------
+(CGFloat)heightForcell:(NSString *)content
{
    //参数1.设置计算内容的宽和高
    //参数2.设置计算高度模式
    //参数3.设置计算字体大小属性
    //参数4.系统备用参数,设置为nil
    //其中宽度一定与显示内容的label宽度一致否则计算不准确  高度尽量大一些
    CGSize size=CGSizeMake(295*WIDTH, 10000);
    //字体大小一定与显示内容的label字体大小一致  默认是17.0
    NSDictionary *dic =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17.0] forKey:NSFontAttributeName];
    
    CGRect frame=  [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
